<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <title>未通过审核订单明细</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <style type="text/css">
        div.group-info {
            margin-top: 10px !important;
            margin-bottom: 0px !important;
        }
        input.innerInput {
            width: 100%;
        }
        div.tablediv {
            width: 1100px;
            margin: auto;
            margin-top: 20px;
            margin-bottom: 20px;
            border-top: 1px solid #cecece;
        }
        td.ui-sgcollapsed.sgexpanded>div, td.ui-sgcollapsed.sgcollapsed>div {
            width: 20px !important;
        }
        tr.ui-subgrid>td.subgrid-data {
            border-right: 1px solid #cecece;
            border-bottom: 1px solid #cecece;
        }
        div.tablediv div.ui-jqgrid-bdiv, div.tablediv div.ui-jqgrid-hdiv {
            border-right: 0px none;
            border-bottom: 0px none;
        }
        span.addRow {
            width: 20px;
            display: block;
            margin: auto;
            cursor: pointer;
        }
        td.subgrid-data {
            background-color: #FDF5E6;
        }
        div.tablediv {
            border-right: 1px solid #cecece;
            border-bottom: 1px solid #cecece;
        }
        .text-left{
            color:#949494;
        }
    </style>
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">     
     <section class="content" >
        <form id="form" class="form-horizontal"  method="post">
            <input type="hidden" name=orderPackId value="${orderPackId}" />
            <table class="infoBox" style="margin-top:5px">
              <tr>
               <td width="150px" class="infoBoxleft" style="background:url(${ctx}/lib/img/img.png)  no-repeat 40px 12px;">
               <td>
                <div class="box-body" style="background:url(${ctx}/lib/img/infobg.png) no-repeat bottom right;">   
                  <div class="form-group form-group-xs"  style="margin-top:2px;">
                    <label class="col-sm-2 text-right" for="inputTextAlter1"><spring:message code="message.listForm.DingDanBaoHao"/><spring:message code="message.yanZheng.maoHao"/></label>
                    <div class="col-sm-4 text-left" >${orderPackId}</div>
                    <label class="col-sm-2 text-right" for="inputTextAlter2"><spring:message code="message.lable.yiLiaoJiGouMingCheng"/><spring:message code="message.yanZheng.maoHao"/></label>
                    <div class="col-sm-4 text-left" id="hospName">${orderPack.hospName}</div>
                  </div>  
                   <div class="form-group form-group-xs"  style="margin-top:-13px;">
                    <label class="col-sm-2 text-right" for="inputTextAlter1"><spring:message code="message.listForm.YiLiaoJiGouDiQu"/><spring:message code="message.yanZheng.maoHao"/></label>
                    <div class="col-sm-4 text-left" id="areaName">${orderPack.hospArFullname}</div>
                    <label class="col-sm-2 text-right" for="inputTextAlter2"><spring:message code="message.listForm.CaiGouShiJian"/><spring:message code="message.yanZheng.maoHao"/></label>
                    <div class="col-sm-4 text-left" id="submitDateTime">${orderPack.submitDatetime}</div>
                  </div>  
                  <div class="form-group form-group-xs" style="margin-top:-13px;">                    
                    <label class="col-sm-2 text-right" for="recpUser"><spring:message code="message.listForm.ShouHuoRen"/><spring:message code="message.yanZheng.maoHao"/></label>
                    <div class="col-sm-4 text-left" id="recpUser">${orderPack.recpUser}</div>
                    <label class="col-sm-2 text-right" for="recpUserPhone"><spring:message code="message.lable.ShouHuoRenDianHua"/><spring:message code="message.yanZheng.maoHao"/></label>
                    <div class="col-sm-4 text-left" id="recpUserPhone">${orderPack.recpUserphone}</div>
                </div>
                <div class="form-group form-group-xs" style="margin-top:-13px;margin-bottom:0px;">                    
                    <label class="col-sm-2 text-right" for="recpAddr"><spring:message code="message.listForm.ShouHuoDiZhi"/><spring:message code="message.yanZheng.maoHao"/></label>
                    <div class="col-sm-9 text-left" id="recpAddr">${orderPack.recpAddr}</div>
                </div>
             </div>
       
        </td>
      </tr>
      </table>
            
            
        </form>

        <div class=" box box-success">
            <div class="box-body">
                <div class="input">
                    <div class="textalign1"><spring:message code="message.listForm.tongYongMing"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="drugName" name="drugName" placeholder="<spring:message code="message.listForm.tongYongMing"/>/<spring:message code="message.listForm.pinYinMa"/>" />
                    </div>
                    <div class="textalign"><spring:message code="message.listForm.ShengChanQiYe"/><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                         <input type="text" class="textinput" id="prodComp" name="prodComp"  placeholder="<spring:message code="message.listForm.ShengChanQiYe"/>/<spring:message code="message.listForm.pinYinMa"/>" />
                    </div>
                    <div class="textalign" >  
                   <button type="button" onclick="gridSerch();" class="btn btn-success btn-sm"  id="selectDicCompType"><spring:message code="message.button.seachSpacing"/></button>
                    </div>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
         <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
            <button type="button" onclick="toSubmits();" class="btn btn-primary btn-sm">保存</button>
            <button type="button" onclick="removeDel();" class="btn btn-danger btn-sm">删除</button>
            <button type="button" onclick="toSubmit();" class="btn btn-primary btn-sm">提交</button>
            </div>
        
   </section>
    
   <%@ include file="/WEB-INF/component/commonJS.jsp"%>
   <script type="text/javascript">
   $(function () {
       //绑定回车
       $('#drugName,#drugCode,#prodComp').bind('keydown', function(event) {
           if (event.keyCode == "13") {
               $('#selectDicCompType').click();
           }
       });  
     
       $("#drugName").focus();//加载页面光标在第一个查询框内
       
       $("#gridlist").jqGrid({
           url: "${ctx}/noOrderConfirm/getPurOrderNotConfirmDteail.html",
       //    url: "${ctx}/purOrderInfo/getOrderDetailByComp.html",
           mtype: "POST",
           postData:{"orderPackId":"${orderPackId}"},
           datatype: "json",
           autowidth: true,
           shrinkToFit: false,
           height: 250,
           colNames: [
                'orderCode',
                '<spring:message code="message.listForm.CaiGouJia"/>',
                '<spring:message code="message.listForm.CaiGouShuLiang"/>',
				'<spring:message code="message.jieSuan.daoHuoShuLiang"/>',
                '<spring:message code="message.listForm.CaiGouJinE"/>',
                '<spring:message code="message.listForm.yaoPinBianMa"/>',
                '<spring:message code="message.listForm.tongYongMing"/>', 
                '<spring:message code="message.listForm.jiXing"/>',
                '<spring:message code="message.listForm.guiGe"/>',
                '<spring:message code="message.listForm.zhuanHuanXiShu"/>',
                '<spring:message code="message.listForm.baoZhuangDanWei"/>', 
                '<spring:message code="message.listForm.shengChanQiYe"/>',
                '国药准字',
                '<spring:message code="message.listForm.CaiGouXianJia"/>',
                '最高零售限价',
                'orderStatus',
               
            ],
            colModel: [
                { name: 'orderCode', width: 60, align: "right",sortable:false, hidden:true },
                { name: 'proPrice', width: 70, align: "right",sortable:false,
                    formatter:function(cellvalue, options, row){
                        return formatAmount(cellvalue, options, row);
                    }
                },
                { name: 'proCount', width: 80, align: "center",sortable:false},
				{ name: 'recpCount', width: 80, align: "center",sortable:false},
                { name: 'orderMoney', width: 80, align: "right",sortable:false,
                    formatter:function(cellvalue, options, row){
                        return formatAmount(cellvalue, options, row);
                    }
                },
                { name: 'drugCode', width: 120, hidden:true, align: "center",sortable:false,
                    formatter:function(cellvalue, options, row){
                        // return drugInfoLink(cellvalue);
                        return cellvalue;
                    }
                },
                { name: 'drugName', width: 160, align: "left" ,sortable:false },
                { name: 'formName', width: 80 , align: "center",sortable:false},
                { name: 'specName', width: 70, align: "center" ,sortable:false},
                { name: 'factor', width: 60, align: "center" ,sortable:false},
                { name: 'unitName', width: 60, align: "center" ,sortable:false},
                { name: 'prodCompname', width: 190, align: "left",sortable:false,
                    formatter:function(cellvalue, options, row){
                        // return compInfoLink(row.prodCompcode, cellvalue, 1);
                        return cellvalue;
                    }
                },
                { name: 'drugMedicine', width: 80 , align: "center",sortable:false},

                { name: 'proPriceLimit', width: 60,align:"right",sortable:false, hidden:true,
                    formatter:function(cellvalue, options, row){
                        return formatAmount(cellvalue, options, row);
                    }
                },
                { name: 'retailPriceLimit', width: 60,align:"right",sortable:false, hidden:true,
                    formatter:function(cellvalue, options, row){
                        return formatAmount(cellvalue, options, row);
                    }
                },
                { name: 'orderStatus', width: 60, align: "center" ,sortable:false, hidden:true},
               
            ],
           rowNum: 20,
           rowList: [10, 20, 50, 100],
           rownumbers: true,
           pager: "#gridpage",
           multiselect: true, 
           viewrecords: true,
           gridComplete: function(){
               //序号列宽度自适应（参数为jqgridID）
               // autoRNWidth("gridlist");
        	   var ids = jQuery("#gridlist").jqGrid('getDataIDs');
       		for(var i=0;i < ids.length;i++){
       			var id = ids[i];
       			var rowdata = $("#gridlist").jqGrid('getRowData', id);
       			var orderMoney = rowdata.proPrice * 10000 * rowdata.proCount / 10000;
       			a = "<input class=\"\" style=\"width:75px;text-align: right;\" type=\"text\" name=\"proCount\" id=\"proCount"+id+"\" onclick=\"selectId("+id+")\" onblur=\"changeAllPrice("+id+");\" value=\""+rowdata.proCount+"\" />";
       			b = "<span id=\"proMoneyId"+id+"\">"+formatAmount(orderMoney)+"</span>";
    			c = "<input class=\"\" style=\"width:75px;text-align: right;\" type=\"text\" id=\"proPrice"+id+"\" value=\""+rowdata.proPrice+"\" />"; 
       			if ("${isSetPlanPrice}" == "true"){
                 	   if (rowdata.lsBackDrugFlag == "true"){
                 		   a = "<input class=\"\" style=\"width:75px;text-align: right;\" type=\"hidden\" name=\"proCount\" id=\"proCount"+id+"\" onclick=\"selectId("+id+")\" onblur=\"changeAllPrice("+id+");\" value=\""+rowdata.proCount+"\" />"+rowdata.proCount;
                 		  c = rowdata.proPrice;
                 	   }
                    } else {
                    	c = rowdata.proPrice;
                   	 if (rowdata.lsBackDrugFlag == "true" && "${bakBatchBuy}" != "true"){
                   		   a = "<input class=\"\" style=\"width:75px;text-align: right;\" type=\"hidden\" name=\"proCount\" id=\"proCount"+id+"\" onclick=\"selectId("+id+")\" onblur=\"changeAllPrice("+id+");\" value=\""+rowdata.proCount+"\" />"+rowdata.proCount;
                   	   }
                    }
       			jQuery("#gridlist").jqGrid('setRowData',ids[i],{proCount:a,orderMoney:b,proPrice:c});
       		}	
       		$($("input[name='proCount']")).keyup(function(event){
               	  var num =$(this).attr("id").replace(/([^0-9])/ig,'');
               	  changeSelectChecked("#gridlist",num,$(this).val(),event);
                 }); 
       	},
       	caption: "订单明细列表 &nbsp;&nbsp;总金额：${amount}",
        jsonReader: {
            repeatitems: false,
            id: "orderCode"
        },
        /* loadComplete: function (data) { //完成服务器请求后，回调函数
        	$("#gridlist").setCaption("订单明细列表&nbsp;&nbsp;&nbsp;总金额：<label id=\"amount\">"+data.amount+"</label>");
        } */
       });
       $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
       $(window).trigger("resize");
       $("html").scrollTop(305);
   });
   
   // onclick="selectId"
   function selectId(id){
			jQuery('#gridlist').jqGrid('setSelection',id);
		}
   //失去焦点
   function changeAllPrice(id){
		var orderMoney = 0;
		orderMoney = Number(orderMoney);
		var rowdata = $("#gridlist").jqGrid('getRowData', id);
		var price = rowdata.proPrice * 10000 * ($("#proCount"+id).val())/ 10000;
		$("#proMoneyId"+id).html(formatAmount(price))
			 
		 var obj= $("#gridlist").jqGrid('getRowData');
		 for (var i=1 ; i <= obj.length; i++) {
			 orderMoney +=Number($('#proMoneyId'+i).html());
		 }
}  
   
   //查询
   function gridSerch() {
       var drugName = $.trim($("#drugName").val());
       var prodComp = $.trim($("#prodComp").val());
       $("#gridlist").jqGrid('setGridParam',{  
           datatype:'json',
           postData:{
               "drugName":drugName,
               "compName":prodComp
           },
           page:1
       }).trigger("reloadGrid"); //重新载入  
   }
   
  
   
   
   //删除
   function removeDel(){
	    var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
		if (rowIds.length <= 0) {
			$.HN.message.alert("请选择要刪除的订单！", "<spring:message code="message.HN.alert.type"/>", "warn");
			return;
		}			
		$.HN.message.confirm('确定删除以下订单吗？<br/>', '', '').on(function (e) {
			if (e) {
				var list = [];
				for (var i=0; i<rowIds.length; i++) {
					rowId = rowIds[i];
					var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
					list.push({"orderCode":rowdata.orderCode});
				}
				$.post("${ctx}/noOrderConfirm/orderInfoDelete.html", {
					"array" : json.jsonToString(list)
					}, function(result) {
						if (result.success) {
							$.HN.message.alert("刪除成功！", "<spring:message code="message.HN.alert.type"/>", "success");
							gridSerch();
						} else {
							$.HN.message.alert("删除失败！", "<spring:message code="message.HN.alert.type"/>", "error");
						}
					}, "json")
			}
		});
	}
   //提交
   function toSubmit(){        	 
 		    var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
 			if (rowIds.length <= 0) {
 				$.HN.message.alert("请选择要提交的订单！", "<spring:message code="message.HN.alert.type"/>", "warn");
 				return;
 			}
 			
 			$.HN.message.confirm('确定提交以下订单吗？<br/>', '', '').on(function (e) {
     			if (e) {
 					var list = [];
 					for (var i=0; i<rowIds.length; i++) {
 						rowId = rowIds[i];
 						var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
 						list.push({"orderPackId":"${orderPackId}"}); 
 					}
 					$.post("${ctx}/noOrderConfirm/orderSubmit.html", {
 						"array" : json.jsonToString(list)
 						}, function(result) {
 							if (result.success) {
 								$.HN.message.alert("提交成功！", "<spring:message code="message.HN.alert.type"/>", "success");
 								window.location.href = "${ctx}/noOrderConfirm/toNotPassOrder.html"; 
 								closeDialog();
 							//	$.alert("<spring:message code="message.HN.alert.success" />", "success", function() {
 							//		window.location.href = "${ctx}/noOrderConfirm/toNotPassOrder.html"; 
 	                        //    }); 
 							} else {
 								$.HN.message.alert("提交失败！", "<spring:message code="message.HN.alert.type"/>", "error");
 							}
 						}, "json")
     			}
     		});
 		}
   function closeDialog() {
       var dialog = top.dialog.get(window);
       //dialog.close("params"); // 关闭（隐藏）对话框
       dialog.remove(); // 主动销毁对话框 
       
   }
   
   </script>
        
</body>
</html>
